//
//  MainViewController.swift
//  weibo-anpeng
//
//  Created by 安鹏 on 16/1/10.
//  Copyright © 2016年 安鹏. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //MARK: 按钮监听事件
    @objc func plusBtnDidClick() {
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
//        print(tabBar.classForCoder)
        let mainTabBar = MainTabBar()
        // 利用kvc简介修改系统的tabBar
        setValue(mainTabBar, forKey: "tabBar")
        mainTabBar.plusBtn.addTarget(self, action: Selector("plusBtnDidClick"), forControlEvents: .TouchUpInside)
//        print(tabBar.classForCoder)
        
        addChildViewControllers()
    }

    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), imageNmae: "tabbar_home", title: "首页")
        
        addChildViewController(MessageTableViewController(), imageNmae: "tabbar_message_center", title: "消息")
        
        addChildViewController(DiscoverTableViewController(), imageNmae: "tabbar_discover", title: "发现")
        
        addChildViewController(ProfileTableViewController(), imageNmae: "tabbar_profile", title: "我")
    }
    
    private func addChildViewController(vc: UIViewController,imageNmae: String,title: String) {
        vc.tabBarItem.image = UIImage(named: imageNmae)
        // tintColor : 设置被选中项的颜色
//        self.tabBar.tintColor = UIColor.orangeColor()
        vc.title = title
        
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
}
